<!-- 需求：用promise链式写法，打印hello world，再答应hello world2，再答应hello world3 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        // //写法1
        // new Promise((resolve, reject) => {
        //     console.log('hello world');
        //     resolve('hello world')
        // }).then(data => {
        //     return new Promise((resolve, reject) => {
        //         console.log(data + "+1");
        //         resolve(data + "+1")
        //     })
        // }).then(data => {
        //     return new Promise((resolve, reject) => {
        //         console.log(data + "+2");
        //     })
        // })

        // //写法2
        // new Promise((resolve, reject) => {
        //     console.log('hello world');
        //     resolve('hello world')
        // }).then(data => {
        //     console.log(data + "+1");
        //     return Promise.resolve(data + "+1")
        // }).then(data => {
        //     console.log(data + "+2");
        // })

        // //写法3
        // new Promise((resolve, reject) => {
        //     console.log('hello world');
        //     resolve('hello world')
        // }).then(data => {
        //     console.log(data + "+1");
        //     return data + "+1"
        // }).then(data => {
        //     console.log(data + "+2");
        // })
    </script>
    <script>
        //上面都是异步操作Fullfill的情况，假如是reject的话
        new Promise((resolve, reject) => {
            console.log('hello world');
            reject('hello world')
        }).catch(data => {
            console.log(data + "+1");
            throw data + "+1"
        }).catch(data => {
            console.log(data + "+2");
        })
    </script>
</body>

</html>